<?php
function mysql_to_short_date($date) {
	global $newDate;
	$dateArray = explode('-',$date);
	$y = substr($dateArray[0],2,2);
	$m = $dateArray[1];
	$d = $dateArray[2];
	$newDate = $m."/".$d."/".$y;
	return $newDate;
}

function timestamp() {
	$today = getdate();
	
	if ($today['hours'] < 10) {
		$hours = "0" . $today['hours'];
	}	
	else {
		$hours = $today['hours']; 
	}
	if ($today['mday'] < 10) {
		$day = "0" . $today['mday'];
	}	
	else {
		$day = $today['mday']; 
	}
		
	$timestamp = $today['year'] . $today['mon'] . $day . $hours . $today['minutes'] . $today['seconds'];
	return $timestamp;
}
 
function short_day() {
$day = date('D');
switch ($day) {
	case "Sun":
	$day = "Sunday";
	break;
	case "Mon":
	$day = "Monday";
	break;
	case "Tue":
	$day = "Tuesday";
	break;
	case "Wed":
	$day = "Wednesday";
	break;
	case "Thu":
	$day = "Thursday";
	break;
	case "Fri":
	$day = "Friday";
	break;
	case "Sat":
	$day = "Saturday";
	break;
	}
	return $day;
	}

function date_to_mysql() { 
$day = date("D"); 
$daynr = date("d"); 
$month = date("F"); 
$year = date("Y");
if ($month == January) { $month = "01"; } 
if ($month == February) { $month = "02"; } 
if ($month == March) { $month = "03"; } 
if ($month == April) { $month = "04"; }
if ($month == May) { $month = "05"; } 
if ($month == June) { $month = "06"; } 
if ($month == July) { $month = "07"; }
if ($month == August) { $month = "08"; } 
if ($month == September) { $month = "09"; } 
if ($month == October) { $month = "10"; }
if ($month == November) { $month = "11"; }  
if ($month == December) { $month = "12"; } 
$mysql_date = "$year-$month-$daynr";
echo $mysql_date;
} 

function mysql_to_date($string_date) {
$dateArray = explode("-", $string_date);
	
	switch ($dateArray[1]) {
	case "01":
	$dateArray[1] = "Jan";	
	break;
	case "02":
	$dateArray[1] = "Feb";
	break;
	case "03":
	$dateArray[1] = "Mar";
	break;
	case "04":
	$dateArray[1] = "Apr";
	break;
	case "05":
	$dateArray[1] = "May";
	break;
	case "06":
	$dateArray[1] = "Jun";
	break;
	case "07":
	$dateArray[1] = "Jul";
	break;
	case "08":
	$dateArray[1] = "Aug";
	break;
	case "09":
	$dateArray[1] = "Sep";
	break;
	case "10":
	$dateArray[1] = "Oct";
	break;
	case "11":
	$dateArray[1] = "Nov";
	break;
	case "12":
	$dateArray[1] = "Dec";
	break;
	}
		
	switch ($dateArray[2]) {
	case "01":
	$dateArray[2] = "1";
	break;
	case "02":
	$dateArray[2] = "2";
	break;
	case "03":
	$dateArray[2] = "3";
	break;
	case "04":
	$dateArray[2] = "4";
	break;
	case "05":
	$dateArray[2] = "5";
	break;
	case "06":
	$dateArray[2] = "6";
	break;
	case "07":
	$dateArray[2] = "7";
	break;
	case "08":
	$dateArray[2] = "8";
	break;
	case "09":
	$dateArray[2] = "9";
	break;
	}	
	$new_date = @mktime(0,0,0,$dateArray[1],$dateArray[2],$dateArray[0]);					 
	$convertedDate = "$dateArray[1] $dateArray[2], $dateArray[0]";
	echo $convertedDate;
	}
	
function mysql_to_date2($string_date) {
global $convertedDate;
$dateArray = explode("-", $string_date);
	
	switch ($dateArray[1]) {
	case "01":
	$dateArray[1] = "Jan";	
	break;
	case "02":
	$dateArray[1] = "Feb";
	break;
	case "03":
	$dateArray[1] = "Mar";
	break;
	case "04":
	$dateArray[1] = "Apr";
	break;
	case "05":
	$dateArray[1] = "May";
	break;
	case "06":
	$dateArray[1] = "Jun";
	break;
	case "07":
	$dateArray[1] = "Jul";
	break;
	case "08":
	$dateArray[1] = "Aug";
	break;
	case "09":
	$dateArray[1] = "Sep";
	break;
	case "10":
	$dateArray[1] = "Oct";
	break;
	case "11":
	$dateArray[1] = "Nov";
	break;
	case "12":
	$dateArray[1] = "Dec";
	break;
	}
		
	switch ($dateArray[2]) {
	case "01":
	$dateArray[2] = "1";
	break;
	case "02":
	$dateArray[2] = "2";
	break;
	case "03":
	$dateArray[2] = "3";
	break;
	case "04":
	$dateArray[2] = "4";
	break;
	case "05":
	$dateArray[2] = "5";
	break;
	case "06":
	$dateArray[2] = "6";
	break;
	case "07":
	$dateArray[2] = "7";
	break;
	case "08":
	$dateArray[2] = "8";
	break;
	case "09":
	$dateArray[2] = "9";
	break;
	}	
	$new_date = @mktime(0,0,0,$dateArray[1],$dateArray[2],$dateArray[0]);					 
	$convertedDate = "$dateArray[1] $dateArray[2], $dateArray[0]";
	return $convertedDate;
	}	

function mysql_to_pdfdate($string_date) {
$dateArray = explode("-", $string_date);
	
	switch ($dateArray[1]) {
	case "01":
	$dateArray[1] = "Jan";	
	break;
	case "02":
	$dateArray[1] = "Feb";
	break;
	case "03":
	$dateArray[1] = "Mar";
	break;
	case "04":
	$dateArray[1] = "Apr";
	break;
	case "05":
	$dateArray[1] = "May";
	break;
	case "06":
	$dateArray[1] = "Jun";
	break;
	case "07":
	$dateArray[1] = "Jul";
	break;
	case "08":
	$dateArray[1] = "Aug";
	break;
	case "09":
	$dateArray[1] = "Sep";
	break;
	case "10":
	$dateArray[1] = "Oct";
	break;
	case "11":
	$dateArray[1] = "Nov";
	break;
	case "12":
	$dateArray[1] = "Dec";
	break;
	}
		
	switch ($dateArray[2]) {
	case "01":
	$dateArray[2] = "1";
	break;
	case "02":
	$dateArray[2] = "2";
	break;
	case "03":
	$dateArray[2] = "3";
	break;
	case "04":
	$dateArray[2] = "4";
	break;
	case "05":
	$dateArray[2] = "5";
	break;
	case "06":
	$dateArray[2] = "6";
	break;
	case "07":
	$dateArray[2] = "7";
	break;
	case "08":
	$dateArray[2] = "8";
	break;
	case "09":
	$dateArray[2] = "9";
	break;
	}	
	$new_date = mktime(0,0,0,$dateArray[1],$dateArray[2],$dateArray[0]);					 
	$convertedDate = "$dateArray[1] $dateArray[2], $dateArray[0]";
	return $convertedDate;
}	
	
function timestamp_to_date($stamp) {
$year = substr("$stamp", 0, 4);
$month = substr("$stamp", 4, 2);
$day = substr("$stamp", 6, 2);
$date =  "$year-$month-$day";
mysql_to_date($date);
}	

function day_convert($day) {
switch ($day) {
	case "01":
	$day = "1";
	break;
	case "02":
	$day = "2";
	break;
	case "03":
	$day = "3";
	break;
	case "04":
	$day = "4";
	break;
	case "05":
	$day = "5";
	break;
	case "06":
	$day = "6";
	break;
	case "07":
	$day = "7";
	break;
	case "08":
	$day = "8";
	break;
	case "09":
	$day = "9";
	break;
	}
return $day;
}

function timestamp_to_time($stamp) {
$hour = substr("$stamp", 8, 2);
$min = substr("$stamp", 10, 2);
switch ($hour) {
	case "00":
	$hour = "12";
	$ampm = "am";
	break;
	case "01":
	$hour = "1";
	$ampm = "am";
	break;
	case "02":
	$hour = "2";
	$ampm = "am";
	break;
	case "03":
	$hour = "3";
	$ampm = "am";
	break;
	case "04":
	$hour = "04";
	$ampm = "am";
	break;
	case "05":
	$hour = "5";
	$ampm = "am";
	break;
	case "06":
	$hour = "6";
	$ampm = "am";
	break;
	case "07":
	$hour = "7";
	$ampm = "am";
	break;
	case "08":
	$hour = "8";
	$ampm = "am";
	break;
	case "09":
	$hour = "9";
	$ampm = "am";
	break;
	case "10":
	$hour = "10";
	$ampm = "am";
	break;
	case "11":
	$hour = "11";
	$ampm = "am";
	break;
	case "12":
	$hour = "12";
	$ampm = "pm";
	break;
	case "13":
	$hour = "1";
	$ampm = "pm";
	break;
	case "14":
	$hour = "2";
	$ampm = "pm";
	break;
	case "15":
	$hour = "3";
	$ampm = "pm";
	break;
	case "16":
	$hour = "4";
	$ampm = "pm";
	break;
	case "17":
	$hour = "5";
	$ampm = "pm";
	break;
	case "18":
	$hour = "6";
	$ampm = "pm";
	break;
	case "19":
	$hour = "7";
	$ampm = "pm";
	break;
	case "20":
	$hour = "8";
	$ampm = "pm";
	break;
	case "21":
	$hour = "9";
	$ampm = "pm";
	break;
	case "22":
	$hour = "10";
	$ampm = "pm";
	break;
	case "23":
	$hour = "11";
	$ampm = "pm";
	break;	
	}

echo "$hour:$min $ampm";
}	

function header_date() {
$day = short_day();
$month = date('F');
$daynr = date('d');
$daynr = day_convert($daynr);
echo "$day, $month $daynr";
}

function month_to_number($month) {
	switch ($month) {
	case "January":
	$num_month = "01";
	break;
	case "February":
	$num_month = "02";
	break;
	case "March":
	$num_month = "03";
	break;
	case "April":
	$num_month = "04";
	break;
	case "May":
	$num_month = "05";
	break;
	case "June":
	$num_month = "06";
	break;
	case "July":
	$num_month = "07";
	break;
	case "August":
	$num_month = "08";
	break;
	case "September":
	$num_month = "09";
	break;
	case "October":
	$num_month = "10";
	break;
	case "November":
	$num_month = "11";
	break;
	case "December":
	$num_month = "12";
	break;
	}
	
	return $num_month;
}

function number_to_month($month_num) {
	switch ($month_num) {
	case "01":
	$month_num = "January";
	break;
	case "02":
	$month_num = "February";
	break;
	case "03":
	$month_num = "March";
	break;
	case "04":
	$month_num = "April";
	break;
	case "05":
	$month_num = "May";
	break;
	case "06":
	$month_num = "June";
	break;
	case "07":
	$month_num = "July";
	break;
	case "08":
	$month_num = "August";
	break;
	case "09":
	$month_num = "September";
	break;
	case "10":
	$month_num = "October";
	break;
	case "11":
	$month_num = "November";
	break;
	case "12":
	$month_num = "December";
	break;
	}
	
	return $month_num;
}
?>